package com.qf.service.impl;

import com.qf.dao.OrderDao;
import com.qf.dao.Showselect;
import com.qf.dao.impl.OrderDaoImpl;
import com.qf.dao.impl.ShowselectImpl;

import com.qf.domain.Goods;
import com.qf.domain.GoodsType;
import com.qf.domain.Order;
import com.qf.domain.User;
import com.qf.service.ShowSelectService;
import com.qf.service.UserService;

import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;


public class ShowSelectServiceimpl implements ShowSelectService {
    private Showselect showselect  = new ShowselectImpl();
    private OrderDao orderDao = new OrderDaoImpl();
    @Override
    public List<User> selectUser(String username, String gender) {
        return showselect.selectUserList(username,gender);
    }

    @Override
    public List<User> selectinvalidUser(String username, String gender) {
        return showselect.selectinvalidUser(username,gender);
    }

    @Override
    public List<GoodsType> selectGoodsType(String name, String level) {
        return showselect.selectGoodsType(name,level);
    }

    @Override
    public List<Goods> selectGoods(String name) {
        return showselect.selectGoods(name);
    }

    @Override
    public List<Order> selectOrder(Integer uid, String status) {
        return showselect.selectOrder(uid,status);
    }

    @Override
    public User select(String username) {
        return showselect.selectUser(username);
    }

    @Override
    public Goods selectGoodsById(Integer id) {
        return showselect.selectGoodsById(id);
    }

    @Override
    public List<Order> selectOrderByName(String username, String status) {
        UserService userService = new UserServiceImpl();
        User user =userService.selectByName(username);
        ArrayList<Order>  list=null;
        if (user!=null){
         list= (ArrayList<Order>) showselect.selectOrderByname(user.getId(),status);
        for (Order order : list) {
            order.setUsername(username);
        }
        }else {
            list = (ArrayList<Order>) orderDao.selectstatus(status);
            for (Order order:list) {
                User user1 = userService.selectById(order.getUid());
                order.setUsername(user1.getUsername());
            }
        }
        return list;
    }
}
